home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / server / message.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  5.7 KB  |  155 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Server side message commands
  8. //-----------------------------------------------------------------------------
  9.  
  10. function messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
  11. {
  12.    commandToClient(%client, 'ServerMessage', %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
  13. }
  14.  
  15. function messageTeam(%team, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
  16. {
  17.    %count = ClientGroup.getCount();
  18.    for(%cl= 0; %cl < %count; %cl++)
  19.    {
  20.       %recipient = ClientGroup.getObject(%cl);
  21.       if(%recipient.team == %team)
  22.           messageClient(%recipient, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
  23.    }
  24. }
  25.  
  26. function messageTeamExcept(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
  27. {
  28.    %team = %client.team;
  29.    %count = ClientGroup.getCount();
  30.    for(%cl= 0; %cl < %count; %cl++)
  31.    {
  32.       %recipient = ClientGroup.getObject(%cl);
  33.       if((%recipient.team == %team) && (%recipient != %client))
  34.           messageClient(%recipient, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
  35.    }
  36. }
  37.  
  38. function messageAll(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
  39. {
  40.    %count = ClientGroup.getCount();
  41.    for(%cl = 0; %cl < %count; %cl++)
  42.    {
  43.       %client = ClientGroup.getObject(%cl);
  44.       messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
  45.    }
  46. }
  47.  
  48. function messageAllExcept(%client, %team, %msgtype, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
  49. {  
  50.    //can exclude a client, a team or both. A -1 value in either field will ignore that exclusion, so
  51.    //messageAllExcept(-1, -1, $Mesblah, 'Blah!'); will message everyone (since there shouldn't be a client -1 or client on team -1).
  52.    %count = ClientGroup.getCount();
  53.    for(%cl= 0; %cl < %count; %cl++)
  54.    {
  55.       %recipient = ClientGroup.getObject(%cl);
  56.       if((%recipient != %client) && (%recipient.team != %team))
  57.          messageClient(%recipient, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
  58.    }
  59. }
  60.  
  61.  
  62. //---------------------------------------------------------------------------
  63. // Server side client chat'n
  64. //---------------------------------------------------------------------------
  65.  
  66. //---------------------------------------------------------------------------
  67. // silly spam protection...
  68. $SPAM_PROTECTION_PERIOD     = 10000;
  69. $SPAM_MESSAGE_THRESHOLD     = 4;
  70. $SPAM_PENALTY_PERIOD        = 10000;
  71. $SPAM_MESSAGE               = '\c3FLOOD PROTECTION:\cr You must wait another %1 seconds.';
  72.  
  73. function GameConnection::spamMessageTimeout(%this)
  74. {
  75.    if(%this.spamMessageCount > 0)
  76.       %this.spamMessageCount--;
  77. }
  78.  
  79. function GameConnection::spamReset(%this)
  80. {
  81.    %this.isSpamming = false;
  82. }
  83.  
  84. function spamAlert(%client)
  85. {
  86.    if($Pref::Server::FloodProtectionEnabled != true)
  87.       return(false);
  88.  
  89.    if(!%client.isSpamming && (%client.spamMessageCount >= $SPAM_MESSAGE_THRESHOLD))
  90.    {
  91.       %client.spamProtectStart = getSimTime();
  92.       %client.isSpamming = true;
  93.       %client.schedule($SPAM_PENALTY_PERIOD, spamReset);
  94.    }
  95.  
  96.    if(%client.isSpamming)
  97.    {
  98.       %wait = mFloor(($SPAM_PENALTY_PERIOD - (getSimTime() - %client.spamProtectStart)) / 1000);
  99.       messageClient(%client, "", $SPAM_MESSAGE, %wait);
  100.       return(true);
  101.    }
  102.  
  103.    %client.spamMessageCount++;
  104.    %client.schedule($SPAM_PROTECTION_PERIOD, spamMessageTimeout);
  105.    return(false);
  106. }
  107.  
  108.  
  109. //---------------------------------------------------------------------------
  110.  
  111. function chatMessageClient( %client, %sender, %voiceTag, %voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  112. {
  113.     //see if the client has muted the sender
  114.     if ( !%client.muted[%sender] )
  115.        commandToClient( %client, 'ChatMessage', %sender, %voiceTag, %voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  116. }
  117.  
  118. function chatMessageTeam( %sender, %team, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  119. {
  120.     if ( ( %msgString $= "" ) || spamAlert( %sender ) )
  121.        return;
  122.     
  123.     %count = ClientGroup.getCount();
  124.     
  125.     for ( %i = 0; %i < %count; %i++ )
  126.     {
  127.        %obj = ClientGroup.getObject( %i );
  128.        if ( %obj.team == %sender.team )
  129.           chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  130.     }
  131. }
  132.  
  133. function chatMessageAll( %sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  134. {
  135.     if ( ( %msgString $= "" ) || spamAlert( %sender ) )
  136.        return;
  137.        
  138.     %count = ClientGroup.getCount();
  139.     
  140.     for ( %i = 0; %i < %count; %i++ )
  141.     {
  142.        %obj = ClientGroup.getObject( %i );
  143.        
  144.        if(%sender.team != 0)
  145.           chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  146.        else
  147.        {
  148.           // message sender is an observer -- only send message to other observers
  149.           if(%obj.team == %sender.team)
  150.              chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  151.        }
  152.     }
  153. }
  154.  
  155.